//
//  JGMetaTool.m
//  JGMeiTuanHD
//
//  Created by JJetGu on 15/9/14.
//  Copyright (c) 2015年 Free. All rights reserved.
//

#import "JGMetaTool.h"

#import "JGCity.h"
#import "JGCategory.h"
#import "JGSort.h"
#import "MJExtension.h"
#import "JGDeal.h"

@implementation JGMetaTool

static NSArray *_cities;
+(NSArray *)cities
{
    if (_cities == nil) {
        _cities = [JGCity objectArrayWithFilename:@"cities.plist"];
    }
    
    return _cities;
}

static NSArray *_categories;
+(NSArray *)categories
{
    if (_categories == nil) {
        _categories = [JGCategory objectArrayWithFilename:@"categories.plist"];;
    }
    
    return _categories;
}

static NSArray *_sorts;
+(NSArray *)sorts
{
    if (_sorts == nil) {
        _sorts = [JGSort objectArrayWithFilename:@"sorts.plist"];
    }
    
    return _sorts;
}

+(JGCategory *)categoryWithName:(NSString *)name
{
    for (JGCategory *category in self.categories) {
        if ([category.name isEqualToString:name]) return category;
        
        // 遍历子类别
        for (NSString *subcategory in category.subcategories) {
            if ([subcategory isEqualToString:name]) return category;
        }
    }
    return nil;
}


@end
